package com.example.springbook.controller;

import com.example.springbook.bean.Borrow;
import com.example.springbook.service.BorrowService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@RestController
@RequestMapping(value = "/borrow")
public class BorrowController {
    @Autowired
    private BorrowService borrowService;

    @RequestMapping(value = "/borrow",method = RequestMethod.POST)
    public boolean addBorrow(@RequestBody Borrow borrow){
//        System.out.println("新增数据：");
        System.out.println("add borrowdata");
        return borrowService.addBorrow(borrow);
    }

    @RequestMapping(value = "/borrow",method = RequestMethod.PUT)
    public boolean updateBorrow(@RequestParam(value = "id",required = true) int id){
        System.out.println("更新数据：");
        return borrowService.updateBorrow(id);
    }

    @RequestMapping(value = "/borrow",method = RequestMethod.DELETE)
    public boolean delete(@RequestParam(value = "id",required = true) int id){
        System.out.println("删除数据：");
        return borrowService.deleteBorrow(id);
    }

    @RequestMapping(value = "/borrowAll",method = RequestMethod.GET)
    public List<Borrow> findAllBorrow(){
//        System.out.println("查询所有数据：");
        System.out.println("findall");
        return borrowService.findAllBorrow();
    }

    @RequestMapping(value = "/findbybook",method = RequestMethod.GET)
    public List<Borrow> findBorrowByBook(@RequestParam(value = "bookid",required = true) int bookid){
//        System.out.println("查询所有数据：");
        System.out.println("findbybook");
        return borrowService.findBorrowByBook(bookid);
    }

    @RequestMapping(value = "/findbyuser",method = RequestMethod.GET)
    public List<Borrow> findBorrowByUser(@RequestParam(value = "userid",required = true) int userid){
//        System.out.println("查询所有数据：");
        System.out.println("findbyuser");
        return borrowService.findBorrowByUser(userid);
    }
}
